home *** CD-ROM | disk | FTP | other *** search
- Path: ausnews.austin.ibm.com!hook
- From: hook@austin.ibm.com (Gary R. Hook)
- Newsgroups: comp.lang.c,comp.os.ms-windows.nt.misc,comp.programming,comp.std.c,comp.unix.aix
- Subject: Re: function pointers
- Date: 1 Feb 1996 01:37:44 GMT
- Organization: AIX Development, IBM Austin
- Sender: hook@shocker.austin.ibm.com (Gary R. Hook)
- Message-ID: <4ep5h8$2pkk@ausnews.austin.ibm.com>
- References: <4eogio$gt0@giga.bga.com>
- NNTP-Posting-Host: shocker.austin.ibm.com
- X-newsreader: xrn 8.01
-
- In article <4eogio$gt0@giga.bga.com>, makuch@bga.com (Michael Makuch) writes:
- > The following c code segment compiles and works on
- > NT MSVC++ and on SVR4 C compiler, but errors out
- > on AIX with a type mismatch;
- >
- > struct foostruct1 * myfoo1();
- > struct foostruct2 * myfoo2();
- > void *(*ptr)();
- >
- > ptr = myfoo1;
- > [snip]
- > ptr = myfoo2;
-
- The code is incorrect. You can only arbitrarily assign to void *
- variables; ptr is no such beast. A cast will work if it is done
- correctly:
-
- ptr = (void *(*)()) myfoo1;
-
- If you cast back, you'll want something like
-
- struct foostruct1 *(*thisfoo)();
-
- thisfoo = (struct foostruct1 *(*)()) ptr;
-
- --
- ________________________________________________________________________
- Gary R. Hook | If you have any trouble sounding
- AIX Development, RS6000 Division | condescending, find a Unix user
- IBM Corporation, Austin, Texas | to show you how it's done.
- The above opinions are all mine. | -Scott Adams, author of "Dilbert"
-